package com.example.app2;

import android.os.Bundle;

import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    private TextView textView;
    private CalendarView calendarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

    }

    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        calendarView = (CalendarView) findViewById(R.id.calendarView);
        final Calendar selectedCalendar = calendarView.getSelectedCalendar();
        //日历选择选择监听
        calendarView.setOnCalendarSelectListener(new CalendarView.OnCalendarSelectListener() {
            @Override
            public void onCalendarOutOfRange(Calendar calendar) {
                //日历超出范围运行
            }

            @Override
            public void onCalendarSelect(Calendar calendar, boolean isClick) {
                //日历选择
                int differ = calendar.differ(selectedCalendar);
                differ=Math.abs(differ);
                textView.setText(
                        "距离今天"+differ+
                        "\n日历："+calendar+
                        "\n农历"+calendar.getLunarCalendar()+
                        "\n农历"+calendar.getLunar()+
                        "\n节日"+ calendar.getGregorianFestival()+
                        "\n日历格式化："+calendar.getDay()+"日"+calendar.getMonth()+"月"+calendar.getYear()+"年"+
                        "\n正在单击："+isClick);
            }
        });
        calendarView.setOnCalendarLongClickListener(new CalendarView.OnCalendarLongClickListener() {
            @Override
            public void onCalendarLongClickOutOfRange(Calendar calendar) {
            }

            @Override
            public void onCalendarLongClick(Calendar calendar) {
                //长按监听
                Toast.makeText(MainActivity.this,"你长按了"+calendar,Toast.LENGTH_SHORT).show();
            }
        });
    }
}
